/**
 * 
 */
package com.dst.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.dst.domain.LoginSystem;

/**
 * @author DT84305
 *
 */
@Repository
public class LoginSystemDaoImpl implements LoginSystemDao {

	/* (non-Javadoc)
	 * @see com.dst.dao.LoginSystemDao#getLoginInfo(java.lang.String, java.lang.String)
	 */
	@Override
	public LoginSystem getLoginInfo(String username, String password) {
		EntityManagerFactory factory = Persistence.createEntityManagerFactory("persistenceUnit");
		EntityManager manager = factory.createEntityManager();
		Query query = manager.createNativeQuery("SELECT USERID FROM LOGINSYSTEM WHERE USERNAME = ? AND PASSWORD = ?", LoginSystem.class);
		query.setParameter(1, username);
		query.setParameter(2, password);
		List<LoginSystem> loginInfoList = query.getResultList();
		if(loginInfoList == null || loginInfoList.isEmpty())
			return null;
		return loginInfoList.get(0);
	}
}
